import java.util.Scanner;


public class Cows {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		String computerChoice = "";

		int num1=0, num2=0, num3=0, num4=0;
		
		num1 = (int)(Math.random()*10);
		
		do{
			num2 = (int)(Math.random()*10);
		}while(num2==num1);
		
		do{
			num3 = (int)(Math.random()*10);
		}while(num3==num1||num3==num2);
		
		do{
			num4 = (int)(Math.random()*10);
		}while(num4==num1||num4==num2||num4==num3);
		
		
		computerChoice=""+num1+num2+num4+num3;
		
		System.out.println( computerChoice );
		int i = 0;
		int cows = 0;
		int bulls = 0;
		
		while(bulls<4){
			cows = 0;
			bulls = 0;
			System.out.print("Please enter your number: ");
			String userGuess=sc.nextLine();
			int counter=0;
			for(i=0; i<userGuess.length(); i++){
				for(int j =i+1; j<userGuess.length(); j++){
					if(userGuess.charAt(i)==userGuess.charAt(j)){
						counter++;
						break;
					}
				}
				
			}
			while((userGuess.length()!=4)||counter>0){
				System.out.print("Please enter a VALID number: ");
				 userGuess=sc.nextLine();
				 counter=0;
				for(i=0; i<userGuess.length(); i++){
					 userGuess.charAt(i);
					for(int j =i+1; j<userGuess.length(); j++){
						if(userGuess.charAt(i)==userGuess.charAt(j)){
							counter++;
						}
					}
					
				}
			}
				
			for( i = 0; i<computerChoice.length(); i++){
				if(computerChoice.charAt(i)==userGuess.charAt(i)){
					bulls++;
					
				}
			}
			for( i=0; i<userGuess.length(); i++){
				for (int j = 0; j<computerChoice.length(); j++){
					if(computerChoice.charAt(j)==userGuess.charAt(i)&&(!(i==j))){
						cows++;
					}
				}
			}
			System.out.println("You have "+bulls+" bulss"+ " and "+ cows+ " cows!");
			System.out.println();
			
		}
			
		System.out.println("Correct! You win!!!");
			
		}


	}


